use std::path::PathBuf;

pub struct Flags {
    pub cmd: SubCommand,
    pub paths: Vec<PathBuf>,
}

impl Flags {
    pub fn parse(args: &[String]) -> Self { 
        match args.len() {
            0 => panic!("No arguments provided."),
            1 => {
                Flags {
                    cmd: SubCommand::parse(&args[0]),
                    paths: Vec::new()
                }
            }
            _ => {
                Flags {
                    cmd: SubCommand::parse(&args[0]),
                    paths: args[1..].iter().map(|p| PathBuf::from(p)).collect(),
                }
            }
        }
    }
}

#[derive(Debug, Clone, Default)]
pub enum SubCommand {
    /// Build
    #[default]
    Build,
    /// Build distribution artificats
    Dist,
}

impl SubCommand {
    pub fn parse(cmd: &str) -> SubCommand {
        match cmd.to_lowercase().as_str() {
            "build" => SubCommand::Build,
            "dist"=> SubCommand::Dist,
            _ => panic!("Failed to identify command.")
        }
    }
}